﻿using System;
using System.Collections.Generic;
using System.Text;
using PacMan3D.Utils;
using Tao.FreeGlut;
using Tao.OpenGl;

namespace PacMan3D.Objects.Models
{
    public class GhostModel : IRenderable
    {
        private int DisplayListId = 0;

        public GhostModel(float radius, int slices, int stacks, RGBAColor bodyColor)
        {
            this.DisplayListId = Gl.glGenLists(1);
            Gl.glNewList(this.DisplayListId, Gl.GL_COMPILE);
            ///
            /// ghost body
            /// 
            Gl.glColor4f(bodyColor.Red, bodyColor.Green, bodyColor.Blue, bodyColor.Alpha);
            Gl.glPushMatrix();
            Gl.glTranslatef(0.0f, -radius / 2.0f, 0.0f);
            Gl.glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
            Gl.glTranslatef(0.0f, 0.0f, -radius / 2.0f);
            Glut.glutSolidCylinder(radius, radius, slices, stacks);
            Gl.glPopMatrix();
            ///
            /// ghost head
            /// 
            Glut.glutSolidSphere(radius, slices, stacks);
            ///
            /// ghost right eye
            /// 
            Gl.glPushMatrix();
            Gl.glTranslatef(-0.7f * radius, radius / 2.0f, radius / 2.0f);
            Gl.glColor4f(1.0f, 1.0f, 1.0f, bodyColor.Alpha);
            Glut.glutSolidSphere(0.2f * radius, slices, stacks);
            Gl.glTranslatef(-0.15f * radius, 0.0f, 0.0f);
            Gl.glColor4f(0.0f, 0.0f, 0.0f, bodyColor.Alpha);
            Glut.glutSolidSphere(0.1f * radius, slices, stacks);
            Gl.glPopMatrix();
            ///
            /// ghost left eye
            /// 
            Gl.glPushMatrix();
            Gl.glTranslatef(-0.7f * radius, radius / 2.0f, -radius / 2.0f);
            Gl.glColor4f(1.0f, 1.0f, 1.0f, bodyColor.Alpha);
            Glut.glutSolidSphere(0.2f * radius, slices, stacks);
            Gl.glTranslatef(-0.15f * radius, 0.0f, 0.0f);
            Gl.glColor4f(0.0f, 0.0f, 0.0f, bodyColor.Alpha);
            Glut.glutSolidSphere(0.1f * radius, slices, stacks);
            Gl.glPopMatrix();
            Gl.glEndList();
        }

        /// <summary>
        /// Método que desenha um Ghost centrado na origem a olhar para -X.
        /// </summary>
        public override void  DrawObject()
        {
            Gl.glPushMatrix();
            Gl.glCallList(this.DisplayListId);
            Gl.glPopMatrix();
        }
    }
}
